package com.tangsm.spring.boot.strategy.controller;

import com.tangsm.spring.boot.strategy.order.enums.OrderEnum;
import com.tangsm.spring.boot.strategy.order.context.OrderContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * Java 枚举实现策略模式测试服务接口
 *
 * @author tangsm
 */
@RestController
@RequestMapping("/java/annotation")
public class JavaAnnotationController {
    /**
     * 阿里支付
     *
     * @param amount 支付金额
     * @return 响应结果
     */
    @GetMapping("/ali/{amount}")
    public String aliOrder(@PathVariable(name = "amount") BigDecimal amount) {
        OrderContext orderContext = new OrderContext(OrderEnum.ALI.getCode());
        return orderContext.placeOrder(amount);
    }

    /**
     * 微信支付
     *
     * @param amount 支付金额
     * @return 响应结果
     */
    @GetMapping("/wx/{amount}")
    public String wxOrder(@PathVariable(name = "amount") BigDecimal amount) {
        OrderContext orderContext = new OrderContext(OrderEnum.WX.getCode());
        return orderContext.placeOrder(amount);
    }

    /**
     * 华为支付
     *
     * @param amount 支付金额
     * @return 响应结果
     */
    @GetMapping("/hw/{amount}")
    public String hwOrder(@PathVariable(name = "amount") BigDecimal amount) {
        OrderContext orderContext = new OrderContext(OrderEnum.HW.getCode());
        return orderContext.placeOrder(amount);
    }

    /**
     * 银联支付
     *
     * @param amount 支付金额
     * @return 响应结果
     */
    @GetMapping("/union/{amount}")
    public String unionOrder(@PathVariable(name = "amount") BigDecimal amount) {
        OrderContext orderContext = new OrderContext(OrderEnum.UNION.getCode());
        return orderContext.placeOrder(amount);
    }

    /**
     * 自定义订单
     *
     * @param code   订单类型编码
     * @param amount 支付金额
     * @return 响应结果
     */
    @GetMapping("/custom/{code}/{amount}")
    public String customOrder(@PathVariable(name = "code") String code, @PathVariable(name = "amount") BigDecimal amount) {
        OrderContext orderContext = new OrderContext(code);
        return orderContext.placeOrder(amount);
    }
}
